package com.example.controller;

import com.example.client.TestFeignClient;
import com.example.config.DemoConfig;
import com.example.event.DemoEventService;
import com.zqli.util.LzqDateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("demo")
public class DemoController {

    @Resource
    private DemoConfig demoConfig;

    @Autowired
    private TestFeignClient testFeignClient;

    @Autowired
    private DemoEventService eventService;

    @GetMapping("/test1")
    public String demo1() {
        return demoConfig.toString();
    }

    @GetMapping("/test2")
    public String demo2() {
//        return testFeignClient.testMethod1123123123();
        return testFeignClient.demo1();
    }

    @DeleteMapping("/test3/{id}")
    public String demo3(@PathVariable String id) {
        return id;
    }

    @GetMapping("/test4/{id}")
    public String demo4(@PathVariable("id") String id) {
        return id;
    }

    @GetMapping("/test5")
    public String demo5(@RequestParam("id") String id) {
        return id;
    }

    // todo 在浏览器调用
    @PostMapping("/test6")
    public String demo6(@RequestParam("id") String id) {
        return id;
    }

    @GetMapping("/testEvent")
    public String eventDemo() {
        eventService.publish("历史课");
        return "success";
    }

    @GetMapping("/testMaven")
    public Long testMaven() {
        return LzqDateUtil.betweenDay("2019-09-20 17:35:35", "2019-09-30 17:35:35");
    }
}
